Skip to content

add support for datetime database functions #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 11, 2024

Conversation

timgraham
Copy link
Collaborator

@timgraham timgraham commented May 24, 2024

fixes #9

@timgraham timgraham force-pushed the datelookups branch 7 times, most recently from 6cfb08e to 28877d2 Compare May 29, 2024 15:59
@timgraham timgraham force-pushed the datelookups branch 5 times, most recently from b784710 to 4d59f1f Compare June 7, 2024 21:41
@timgraham timgraham changed the title implement date lookups add support for datetime database functions Jun 7, 2024
@timgraham timgraham marked this pull request as ready for review June 7, 2024 22:02
@timgraham timgraham requested review from WaVEV and Jibola June 10, 2024 13:41
Copy link
Contributor

@Jibola Jibola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Left a couple questions of commentary.

@@ -63,7 +63,7 @@ jobs:
- name: Start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: 4.4
mongodb-version: 5.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reservation to running these tests using at least mongodb version 6.0? Or is the goal to test with our oldest supported version?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4.4 was copied from the pymongo config. I bumped it here because $dateTrunc is new in 5.0. For this CI, I'd suggest using the oldest version we decide to support. That choice doesn't necessarily have to follow MongoDB's supported versions, but thus far, I haven't encountered anything that makes supporting 5.0 more difficult.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. My one hesitation is we may eventually run into a functionality only available in later versions. With that being said, we'll cross that bridge when we get there. I'll file an issue ticket to identify the min-supported version.

ExtractMinute.lookup_name: "minute",
ExtractMonth.lookup_name: "month",
ExtractSecond.lookup_name: "second",
ExtractWeek.lookup_name: "isoWeek",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the switch toisoWeek over week?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Django's ExtractWeek is documented as returning 1-52 or 53, based on ISO-8601, i.e., Monday is the first of the week.

@@ -133,3 +134,43 @@ def _prep_lookup_value(self, value, field, field_kind, lookup):
if field_kind == "DecimalField":
value = self.adapt_decimalfield_value(value, field.max_digits, field.decimal_places)
return value

"""Django uses these methods to generate SQL queries before it generates MQL queries."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we make these SQL queries just for logging/debugging purposes? Could we get away with not rendering them at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we cannot avoid it. It has to do with how this library hooks in to the query generation process. See also:

https://github.com/mongodb-labs/django-mongodb/blob/3c3ad0eb45a2572453aa228ddafac96391dc1ab8/django_mongodb/query.py#L23-L32

as_mql_agg() only needs to be defined if it differs from as_mql()
This feature flag has been added to mongodb-forks/django.
@Jibola Jibola self-requested a review June 11, 2024 15:22
@timgraham timgraham merged commit 8bbfc61 into mongodb:main Jun 11, 2024
3 checks passed
@timgraham timgraham deleted the datelookups branch June 11, 2024 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add support for date lookups
2 participants